require "System::Net"
require "System::Windows::Media"
require "System.Windows.Media.Imaging"
include System

def log(msg)
  document.msg.innerHTML = msg
end

def lightbox(image_src)
  HtmlPage.Plugin.SetStyleAttribute("left", "0px")
  me.desc.Text = image_src
  me.pic.Source = BitmapImage.new(Uri.new(image_src))
  me.fade_in.Begin()
end

def close_lightbox(s=nil,e=nil)
  HtmlPage.Plugin.SetStyleAttribute("left", "-5000px")
end

def setup_canvas()
  HtmlPage.Plugin.SetStyleAttribute("position","absolute")
  HtmlPage.Plugin.SetStyleAttribute("top","0px")
  close_lightbox()
  HtmlPage.Plugin.Width = "100%"
  HtmlPage.Plugin.Height = "100%"
  me.LayoutRoot.MouseLeftButtonDown{|s,e|close_lightbox(s,e)}
end

setup_canvas()
document.thumb.AttachEvent("onclick", EventHandler[HtmlEventArgs].new(lambda {|s,e| lightbox(s.src)}))
document.thumb2.AttachEvent("onclick", EventHandler[HtmlEventArgs].new(lambda {|s,e| lightbox(s.src)}))